package com.yxym.homework01;

public class Person {
    public static void main(String[] args) {
        Person[] person = new Person[3];//创建数组对象
        Person temp  = null;//中间值
        person[0] = new Person(20,"小红","java工程师");
        person[1] = new Person(30,"小强","大数据工程师");
        person[2] = new Person(25,"小明","人工智能");
        for (int i = 0; i < person.length; i++) {
            for (int j = 0; j < person.length-1-i; j++) {

                //1.冒泡排序找出年龄较大的放前面
                if(person[i].getAge() < person[i+1].getAge()){

                    temp = person[i];
                    person[i] = person[i+1];
                    person[i+1] = temp;
                }
                //2.利用字符串的长度进行排序
//                if(person[i].getJob().length() < person[i+1].getJob().length()){
//                    temp = person[i];
//                    person[i] = person[i+1];
//                    person[i+1] = temp;
//                }
            }
            System.out.println(person[i]);//默认输出toString方法
        }
    }
    private int age;
    private String name;
    private String job;

    public Person(int age, String name, String job) {
        this.age = age;
        this.name = name;
        this.job = job;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getJob() {
        return job;
    }

    public void setJob(String job) {
        this.job = job;
    }

    @Override
    public String toString() {
        return "Person{" +
                "age=" + age +
                ", name='" + name + '\'' +
                ", job='" + job + '\'' +
                '}';
    }
}
